<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <style type="text/css">
        body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"微软雅黑";}
    </style>
    <script type="text/javascript" src="//api.map.baidu.com/api?v=2.0&ak=j8pFXUGzQAThvaivRYSQ5jVZLOCBeF0n"></script>
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/vue.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <title>地图展示</title>
</head>
<body>

<div id="allmap"></div>
</body>
</html>

<script type="text/javascript">
    // 百度地图API功能
    var map = new BMap.Map("allmap");
    map.centerAndZoom(new BMap.Point(114.3162,30.581084), 12);
    map.enableScrollWheelZoom(true);
    var index = 0;
    var myGeo = new BMap.Geocoder();
    var adds = [];
    var addNames=[];
   /* function bdGEO(){
        var pt = adds[index];
        geocodeSearch(pt);
        index++;
    }
    function geocodeSearch(pt){
        if(index < adds.length-1){
            setTimeout(window.bdGEO,400);
        }
        myGeo.getLocation(pt, function(rs){
            var addComp = rs.addressComponents;
            // document.getElementById("result").innerHTML += index + ". " +adds[index-1].lng + "," + adds[index-1].lat + "："  + "商圈(" + rs.business + ")  结构化数据(" + addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber + ")<br/><br/>";
        });
    }*/

    var vue = new Vue({
        data:{},
        created(){
            this.init();
        },
        methods:{
            init(){
                axios.get("/company/getAddress.do")
                    .then(resp => {
                        if (resp.data.flag) {
                            //查询成功
                            for (var i = 0; i < resp.data.data.length; i++) {
                                adds[i] = new BMap.Point(resp.data.data[i].longitude,
                                                         resp.data.data[i].latitude);
                                addNames[i] = resp.data.data[i].address_name;

                            }
                            for(var i = 0; i<adds.length; i++){
                                var marker = new BMap.Marker(adds[i]);
                                map.addOverlay(marker);
                                marker.setLabel(new BMap.Label('【'+(i+1)+'】'+addNames[i],{offset:new BMap.Size(20,-10)}));
                            }
                        }
                    })
            }
        }
    });

</script>
